package main

import (
	"github.com/beego/beego/v2/adapter/logs"
	"backend/middlewave"
	_ "backend/routers"

	"github.com/beego/beego/v2/client/orm"
	beego "github.com/beego/beego/v2/server/web"
	_ "github.com/go-sql-driver/mysql"
)

func main() {
	err := orm.RegisterDriver("mysql", orm.DRMySQL)
	if err != nil {
		logs.Error(err.Error())
		return
	}
	sqlConn, _ :=  beego.AppConfig.String("sqlconn")
	logs.Info(sqlConn)
	err = orm.RegisterDataBase("default", "mysql",sqlConn)
	if err != nil {
		logs.Error(err.Error())
	}
	if beego.BConfig.RunMode == "dev" {
		beego.BConfig.WebConfig.DirectoryIndex = true
		beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
	}
	beego.BConfig.RecoverPanic = true
	beego.BConfig.RecoverFunc = middlewave.HandleError // 全局错误处理中间件
	beego.Run()
}

